package DAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ResourceManager {
	private static String driver = "com.mysql.jdbc.Driver";
	private static String serverName = "localhost";
	private static String database = "Estagio";
	private static String porta = "3306";
	private static String url = "jdbc:mysql://" + serverName + ":" + porta
			+ "/" + database;
	private static String userName = "root";
	private static String password = "123456";

	public static synchronized Connection getConnection() {
		Connection con = null;
		try {
			Class.forName(driver);		
			con = DriverManager.getConnection(url, userName, password);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return con;
	}

	public static void close(Connection con) {
		if (con != null)
			try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
}
